//
//  YSGTimer.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/4/13.
//  Copyright © 2020 QDSG. All rights reserved.
//

import UIKit

class YSGTimer: NSObject {
    
    private(set) var timer: Timer!
    
    var fireDate: Date {
        set {
            timer.fireDate = newValue
        }
        get {
            return timer.fireDate
        }
    }
    
    class func scheduledTimer(with timeInterval: TimeInterval, repeats: Bool, block: @escaping (_ timer: Timer) -> Void) -> YSGTimer {
        let timer = YSGTimer()
        timer.timer = Timer.scheduledTimer(withTimeInterval: timeInterval, repeats: repeats, block: block)
        RunLoop.current.add(timer.timer, forMode: .common)
        return timer
    }
    
    func fire() { timer.fire() }
    
    func invalidate() {
        if timer != nil {
            timer.invalidate()
            timer = nil
        }
    }
    
    deinit {
        YSGLog("timer已销毁")
    }
}
